package cn.edu.swpu.cins.u_chain.frontend.controller.team;

import cn.edu.swpu.cins.u_chain.frontend.entity.dto.ResultData;
import cn.edu.swpu.cins.u_chain.frontend.entity.dto.team.TeamDetailInfos;
import cn.edu.swpu.cins.u_chain.frontend.entity.dto.team.TeamPros;
import cn.edu.swpu.cins.u_chain.frontend.entity.persistence.team.TeamInfo;
import cn.edu.swpu.cins.u_chain.frontend.service.team.TeamService;
import com.sun.org.apache.regexp.internal.RE;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("UChain/user/team")
public class TeamController {

    @Autowired
    private TeamService teamService;
    /**
     * 至少要完成团队信息添加 和团队成员添加
     *
     * @return
     */
    @PostMapping("create")
    public ResultData createTeam(@RequestBody TeamInfo teamInfo, @RequestHeader("userId") int userId) {
        teamService.addTeam(teamInfo, userId);
        return new ResultData(true, "创建成功");
    }
    /**
     * 首先通过userId获取teamId
     *
     * @param userId
     * @return
     */
    @GetMapping("getTeamPros/{pageNum}")
    public ResultData getTeamPros(@RequestHeader("userId") int userId, @PathVariable("pageNum") int pageNum) {
        List<TeamPros> teamPros = teamService.getTeamProsByUserId(userId, pageNum);
        return new ResultData(true, "我的团队发布过的项目", teamPros);
    }

    @GetMapping("getTeamDetail/{teamId}")
    public ResultData getTeamDetailInfo(@PathVariable("teamId") int teamId) {
        TeamDetailInfos teamDetailInfos = teamService.selectTeamDetailInfoById(teamId);
        return new ResultData(true, "我加入团队的信息", teamDetailInfos);
    }
}
